import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:photo_frame/utils/localization_util.dart';
import 'package:qr_flutter/qr_flutter.dart';

class ShareFrameDialog extends StatelessWidget {
  final ShareInfo _shareInfo;

  const ShareFrameDialog(this._shareInfo, {super.key});

  @override
  Widget build(BuildContext context) {
    return Dialog(
      backgroundColor: Color(0xff3D3D3D),
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(12.0),
      ),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Padding(
            padding: const EdgeInsets.all(25.5),
            child: Row(
              children: [
                QrImageView(
                    data: _shareInfo.code,
                    version: QrVersions.auto,
                    size: 90,
                    backgroundColor: Colors.white),
                SizedBox(width: 14.5),
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Padding(
                      padding: const EdgeInsets.only(top: 3),
                      child: Text(
                          "${AppLocalizationsWrapper.instance.unwrap(context).pairingCode}：",
                          style: TextStyle(fontSize: 14, color: Colors.white)),
                    ),
                    Text(_shareInfo.code,
                        style: TextStyle(fontSize: 28, color: Colors.white)),
                    SizedBox(height: 10),
                    Text(
                        "${AppLocalizationsWrapper.instance.unwrap(context).periodOfValidity}：${_shareInfo.expirationDate}",
                        style: TextStyle(fontSize: 9, color: Colors.white)),
                  ],
                )
              ],
            ),
          ),
          Divider(
            height: 1,
            color: Color(0xff979797),
          ),
          CupertinoButton(
            padding: EdgeInsets.zero,
            onPressed: () {
              Clipboard.setData(ClipboardData(text: _shareInfo.code));
              Fluttertoast.showToast(
                  msg: AppLocalizationsWrapper.instance
                      .unwrap(context)
                      .copySuccessful);
            },
            child: Container(
              height: 46,
              child: Center(
                child: Text(
                  AppLocalizationsWrapper.instance.unwrap(context).copy,
                  style: TextStyle(
                      fontSize: 16,
                      color: Colors.white,
                      fontWeight: FontWeight.bold),
                ),
              ),
            ),
          )
        ],
      ),
    );
  }
}

class ShareInfo {
  final String code;
  final String expirationDate;

  ShareInfo(
    this.code,
    this.expirationDate,
  );
}
